package com.tqfframe.rabbitmq.controller;

import com.tqfframe.rabbitmq.constants.RabbitConstants;
import com.tqfframe.rabbitmq.service.DelayService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: Qifeng Tang
 * @date: 2022/8/31 11:15
 * @Version 1.0
 **/
@RestController
public class DirectController {

    @Autowired
    RabbitTemplate rabbitTemplate;
    @Autowired
    DelayService delayService;

    /**
     * 发送普通消息
     *  http://localhost:8080/commonMsg
     * @return
     */
    @GetMapping("/commonMsg")
    private String commonMsg(){
        //使用队列名进行发送，就不用填交互机
//        rabbitTemplate.convertAndSend(RabbitConstants.COMMON_QUEUE, "hello word!，你好");
        //使用交互机加路由进行发送
        rabbitTemplate.convertAndSend(RabbitConstants.COMMON_EXCHANGE,RabbitConstants.COMMON_ROUTINGKEY, "hello word!，你好");
        System.out.println("发送成功");
        return "11";
    }


}
